package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.adapter.ADA_SwimHistoryList;
import com.egg.ylt.controls.HEAD_SwimHistroy;
import com.egg.ylt.pojo.SwimHistoryEntity;
import com.egg.ylt.pojo.SwimHistoryListEntity;
import com.egg.ylt.presenter.impl.SwimHistoryPresenterImpl;
import com.egg.ylt.view.ISwimHistoryView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author:        yupeng
 * created on:    2019/2/25 17:54
 * description:   游泳纪录
 */
public class ACT_SwimHistory extends BaseActivity<SwimHistoryPresenterImpl> implements ISwimHistoryView {

    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.include_tv_right)
    TextView includeTvRight;
    @BindView(R.id.include_rl_view)
    RelativeLayout includeRlView;
    @BindView(R.id.xRecyclerView)
    XRecyclerView xRecyclerView;
    @BindView(R.id.ll_target_view)
    LinearLayout llTargetView;

    private HEAD_SwimHistroy headerView;
    private ADA_SwimHistoryList adapter;

    @Override
    public void showSwimHistory(SwimHistoryEntity swimHistoryEntity) {
        headerView.showSwimHistory(swimHistoryEntity);
    }

    @Override
    public void showSwimHistoryList(SwimHistoryListEntity swimHistoryListEntity, boolean isRefresh) {
        adapter.update(swimHistoryListEntity.getList(), isRefresh);
    }

    @Override
    public void stopListViewRefreshAndLoadMore() {
        xRecyclerView.refreshComplete();
        xRecyclerView.loadMoreComplete();
    }

    @Override
    public void setListViewToLastPageAndNoData(boolean isLastPage, boolean isNoData) {
        if (isNoData) {
            // 如果没有任何数据, 需要隐藏 已经到达最后一条的显示
            xRecyclerView.setNoMore(false);
        } else {
            xRecyclerView.setNoMore(isLastPage);
        }
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_swim_history;
    }

    @Override
    protected View getLoadingTargetView() {
        return llTargetView;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.color_F4F4F4);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, includeRlView);

        includeTvTitle.setText("健康记录");

        headerView = new HEAD_SwimHistroy(this);
        xRecyclerView.addHeaderView(headerView);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        xRecyclerView.setLayoutManager(layoutManager);
        xRecyclerView.setFootViewText("正在加载...", "已经是最后一条数据了.");
        xRecyclerView.setPullRefreshEnabled(true);
        xRecyclerView.setLoadingMoreEnabled(true);
        xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                mPresenter.onRefresh();
            }

            @Override
            public void onLoadMore() {
                mPresenter.onLoadMore();
            }
        });

        adapter = new ADA_SwimHistoryList(mContext);
        xRecyclerView.setAdapter(adapter);

        mPresenter.onInit();
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @OnClick({R.id.include_iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.include_iv_back:
                finish();
                break;
        }
    }

}
